using System.Collections;
using UnityEngine;

namespace NodeCanvas
{
	public abstract class ConditionTask : Task
	{
		[SerializeField]
		private bool invertCondition;

		private int yieldReturn = -1;

		private bool initFailed;

		public sealed override string summaryInfo
		{
			get
			{
				return ((!base.agentIsOverride) ? string.Empty : "* ") + ((!invertCondition) ? "If " : "If <b>!</b> ") + info;
			}
		}

		protected virtual string info
		{
			get
			{
				return base.taskName;
			}
		}

		public bool CheckCondition(Component agent)
		{
			return CheckCondition(agent, base.blackboard);
		}

		public bool CheckCondition(Component agent, Blackboard blackboard)
		{
			if (!Set(agent, blackboard))
			{
				initFailed = true;
			}
			if (initFailed)
			{
				return false;
			}
			if (yieldReturn != -1)
			{
				return (!invertCondition) ? (yieldReturn == 1) : (yieldReturn != 1);
			}
			return (!invertCondition) ? OnCheck() : (!OnCheck());
		}

		protected virtual bool OnCheck()
		{
			return true;
		}

		protected void YieldReturn(bool value)
		{
			yieldReturn = (value ? 1 : 0);
			StartCoroutine(Fade());
		}

		private IEnumerator Fade()
		{
			yield return null;
			yieldReturn = -1;
		}
	}
}
